package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chainyoung.common.imageloader.ImageLoader;
import com.chainyoung.common.imageloader.glide.GlideImageConfig;
import com.chainyoung.common.utils.StringUtil;
import com.chainyoung.common.utils.Utils;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.entity.Purse;
import com.chainyoung.component_tmperson.ui.activity.cloudwallet.PurseActivity;

import java.math.BigDecimal;
import java.util.List;


/**
 * 2018/7/25 9:49
 * Created by FREECSDN on 2018/7/25.
 */
public class WalletAdapter extends BaseQuickAdapter<Purse, BaseViewHolder> {

    private ImageLoader imageLoader;

    private boolean isShowAsset = true;

    public WalletAdapter(@Nullable List<Purse> data) {
        super(R.layout.tmperson_layout_wallet_item, data);
        imageLoader = Utils.getAppComponent().imageLoader();
    }


    @Override
    protected void convert(BaseViewHolder helper, final Purse item) {
        helper.setText(R.id.coin_name, item.getName().toUpperCase());
        helper.setText(R.id.coin_num, !isShowAsset ? "****" : StringUtil.subZeroAndDot(new BigDecimal(item.getXnbz()).setScale(6, BigDecimal.ROUND_DOWN) + ""));
        helper.setText(R.id.coin_cny_amount, !isShowAsset ? "****" : "≈CNY " + StringUtil.subZeroAndDot(new BigDecimal(item.getZhehe_cny()).setScale(2, BigDecimal.ROUND_DOWN).toString()));
        // helper.setText(R.id.coin_lock, StringUtil.subZeroAndDot(new BigDecimal(item.getXnbd()).setScale(6,BigDecimal.ROUND_DOWN) + ""));
        imageLoader.loadImage(mContext,
                GlideImageConfig
                        .builder()
                        .url(item.getImg())
                        .imagerView((ImageView) (helper.getView(R.id.coin_logo)))
                        .build());

        helper.getView(R.id.rl_purse).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, PurseActivity.class);
                intent.putExtra("purseItem", item);
                mContext.startActivity(intent);
            }
        });


//        helper.getView(R.id.btn_charge).setOnClickListener(onClickListener);
//        helper.getView(R.id.btn_cash).setOnClickListener(onClickListener);
//        helper.getView(R.id.btn_trade).setOnClickListener(onClickListener);
//
//        helper.getView(R.id.btn_charge).setTag(item);
//        helper.getView(R.id.btn_cash).setTag(item);
//        helper.getView(R.id.btn_trade).setTag(item);
    }

    public void setShowAsset(boolean showAsset) {
        isShowAsset = showAsset;
    }

//    private View.OnClickListener onClickListener = new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            Purse item = (Purse) v.getTag();
//            if (v.getId() == R.id.btn_charge) {
//                Intent intent = new Intent(mContext, ChargeActivity.class);
//                intent.putExtra(COIN_NAME, item.getName());
//                intent.putExtra(COIN_CN_NAME, item.getTitle());
//                mContext.startActivity(intent);
//            } else if (v.getId() == R.id.btn_cash) {
//                Intent intent = new Intent(mContext, MakeCashActivity.class);
//                intent.putExtra(COIN_NAME, item.getName());
//                intent.putExtra(COIN_CN_NAME, item.getTitle());
//                intent.putExtra(ZC_FEE, item.getZcfee());
//                mContext.startActivity(intent);
//            } else if (v.getId() == R.id.btn_trade) {
//                RouterUtils.getInstance()
//                        .build(RouterConstants.PATH_MAIN_MARKET_ACTIVITY)
//                        .withInt("page", 1)
//                        .navigation(mContext);
//            }
//        }
//    };


}
